//会员列表0
//会员详情1

//(function(){
define(function(require,exports,module){
	"require:nomunge,exports:nomunge,module:nomunge";
	
	//异步请求
	var wind_async=require('ddf_wind_async');
		
	var base=require('component-base');
	var history=require('component-history');
	require('component-page');

var beginDate,endDate,beginCredits,endCredits,memberType,realname,username,mobile;

var selectUserId,orderId;

var tips_index=0;
var pageSIze = "";

/**
 * 初始化参数
 */
function initParams(){
	
	
	beginDate="";
	endDate="";
	beginCredits="";
	endCredits="";
	memberType="";
	realname="";
	username="";
	mobile="";
	
}


/**
 * 查询会员列表
 */
//function loadMemberList() {
  exports.init = function(m){
	  history.addHis(this,arguments);//增加历史
	    window.$ddf_member = m;
		initParams();
		pageIndex=0;
		var htmlStr="";
		
		htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:void(0)" class="current">会员管理</a></div></div>';
		htmlStr += '<div class="container-fluid">';
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span12">';
		htmlStr += '<div id="alert-tips0" ></div>';
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title"><span class="icon"><i class="icon-search"></i></span><h5>搜索条件</h5><button type="button" class="label label-success toggle">缩放</button></div>  ';
		htmlStr += '<div class="widget-content nopadding">';
		htmlStr += '<form class="form-horizontal">';
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">创建时间：</label><div class="controls"><input class="span4 m-wrap Wdate" type="text" id="beginDate" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span4 m-wrap Wdate" type="text" id="endDate" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) /></div></div></div>';
		
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">会员等级：</label><div class="controls"><div class="btn-group"><button data-toggle="dropdown" class="btn dropdown-toggle"><span id="levelName">请选择</span>&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu" id="levelList"></ul></div>   <div class="btn-group" id="payStatusDiv" style="display:none;" ><button data-toggle="dropdown" class="btn dropdown-toggle"><span id="payStatusName">全部</span>&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu"></ul></div> </div></div></div>';
		htmlStr += '</div>';
		
		htmlStr += '<div class="row-fluid"> ';
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">会员积分：</label><div class="controls"><input class="span4 m-wrap" type="text" id="beginCredits" />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span4 m-wrap" type="text" id="endCredits" /></div></div></div>';
		
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">会员姓名：</label><div class="controls"><input class="span8 m-wrap" type="text" id="realname"/></div></div></div>';
		htmlStr += '</div> ';
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">用户账号：</label><div class="controls"><input class="span8 m-wrap" type="text" id="username"/></div></div></div>';
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">手机号码：</label><div class="controls"><input class="span8 m-wrap" type="text" id="mobile"/></div></div></div>';
		htmlStr += '</div>   ';
		
		htmlStr += '<div class="form-actions">';
		htmlStr += '<button class="btn btn-primary" type="button" onClick="$ddf_member.searchMember()">搜索</button>';
		htmlStr += ' <button class="btn btn-info" type="button" onClick="$ddf_member.resetSearchParams()">重置</button>';
		htmlStr += '</div>        ';
		htmlStr += '</form>';
		htmlStr += '</div>';
		htmlStr += '</div> ';
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
		htmlStr += '<h5>会员列表</h5>';
		htmlStr += '</div>';
		htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
		htmlStr += '<table class="table table-bordered data-table">';
		htmlStr += '<thead>';
		htmlStr += '<tr>';
		htmlStr += '<th>序号</th>';
		htmlStr += '<th>创建时间</th>';
		htmlStr += '<th>用户账号</th>';
		htmlStr += '<th>会员姓名</th>';
		htmlStr += '<th>会员性别</th>';
		htmlStr += '<th>会员级别</th>';
		htmlStr += '<th>会员积分</th>';
		htmlStr += '<th>手机号码</th>';
		htmlStr += '<th>操作</th>';
		htmlStr += '</tr>';
		htmlStr += '</thead>';
		htmlStr += '<tbody id="memberList">';
		htmlStr += '</tbody>';
		htmlStr += '</table>';
		htmlStr += '<div id="footPageDiv'+pageIndex+'">';

		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>  ';
		htmlStr += '</div>';
		htmlStr += '</div> ';
		htmlStr += '</div> ';

//		$("#content0").css("display", "block");
		showDiv("content0");

		$("#content0").html(htmlStr);
		
		getQueryMemberList(1,pageSize,beginDate,endDate,beginCredits,endCredits,memberType,realname,username,mobile);

		

}

/**
 * 查询会员列表
 */
function getQueryMemberList(pageNumber,pageSize,beginDate,endDate,beginCredits,endCredits,memberType,realname,username,mobile){
	
	var params={
			"page.pageNumber":pageNumber,
			"page.pageSize" : pageSize,
			"beginDate":beginDate,
			"endDate":endDate,
			"beginCredits":beginCredits,
			"endCredits":endCredits,
			"memberType":memberType,
			"mobile":mobile,
			"username":username,
			"realname":realname
	        };
	
	tips_index=0;

	base.showLoading();
	
//	DDF_AsyncRequest("POST",ddf.member.getQueryMember,params,'$ddf_member.getQueryMemberListCallBack(data)');
	 eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.member.getQueryMember,params));
			
			getQueryMemberListCallBack(data);
			
		}))().start();
	
}

/**
 * 查询会员列表_回调函数
 */
function getQueryMemberListCallBack(data){
	
	/*if(data["code"]==1){
		

		var htmlStr = "";

		for (var i = 0; i < data["memberListData"].length; i++) {

			htmlStr += '<tr>';
			htmlStr += '<td>' +getSequence(data["pageNumber"],i+1) + '</td>';
			htmlStr += '<td>'+data["memberListData"][i]["CREATE_TIME"]+'</td>';
			htmlStr += '<td>'+data["memberListData"][i]["USER_NAME"]+'</td>';
			htmlStr += '<td>'+data["memberListData"][i]["REAL_NAME"]+'</td>';
			
			if(data["memberListData"][i]["SEX"]=="1"){
				htmlStr += '<td>男</td>';
			}else{
				htmlStr += '<td>女</td>';
			}
			
			htmlStr += '<td>'+data["memberListData"][i]["LEVEL_NAME"]+'</td>';
			htmlStr += '<td>'+data["memberListData"][i]["CREDITS"]+'</td>';
			htmlStr += '<td>'+data["memberListData"][i]["MOBILE"]+'</td>';
			htmlStr += '<td><a href=javascript:$ddf_member.loadMemberDetail("'+data["memberListData"][i]["USER_ID"]+'")>详情</a></td>';
			htmlStr += '</tr>';

		}


		$("#memberList").html(htmlStr);

		setPage(pageIndex,data["pageNumber"],data["totalCount"],data["totalPage"],"$ddf_member");

		getMemberLevelList("query");



	}else{
		
		 tips_error(tips_index,data["message"]);
	}
*/
   
	if(data["code"]==null){
		base.tips_error("没有查询到符合条件的信息");
		$("#memberList").html("");
//		setPage(pageIndex,"0","0","0","$ddf_member");

	}else{
		if(data["code"]==1){
			

			var htmlStr = "";
			
			

			for (var i = 0; i < data["memberListData"].length; i++) {

				htmlStr += '<tr>';
				htmlStr += '<td>' +getSequence(data["pageNumber"],i+1) + '</td>';
				htmlStr += '<td>'+data["memberListData"][i]["CREATE_TIME"]+'</td>';
				htmlStr += '<td>'+data["memberListData"][i]["USER_NAME"]+'</td>';
				htmlStr += '<td>'+data["memberListData"][i]["REAL_NAME"]+'</td>';
				
				if(data["memberListData"][i]["SEX"]=="1"){
					htmlStr += '<td>男</td>';
				}else{
					htmlStr += '<td>女</td>';
				}
				
				htmlStr += '<td>'+data["memberListData"][i]["LEVEL_NAME"]+'</td>';
				htmlStr += '<td>'+data["memberListData"][i]["CREDITS"]+'</td>';
				htmlStr += '<td>'+data["memberListData"][i]["MOBILE"]+'</td>';
				htmlStr += '<td><a href=javascript:$ddf_member.loadMemberDetail("'+data["memberListData"][i]["USER_ID"]+'")>详情</a></td>';
				htmlStr += '</tr>';

			}


			$("#memberList").html(htmlStr);

//			setPage(pageIndex,data["pageNumber"],data["totalCount"],data["totalPage"],"$ddf_member");
			 $('#footPageDiv0').ddf_pagination(data["pageSize"],data["pageNumber"],data["totalCount"],data["totalPage"],{  
				 changePageCallback:function(pageSize,page){  
					 getQueryMemberList(page,pageSize,beginDate,endDate,beginCredits,endCredits,memberType,realname,username,mobile);
				 },
				 changePageSizeCallBack:function(pageSize){
					 getQueryMemberList(1,pageSize,beginDate,endDate,beginCredits,endCredits,memberType,realname,username,mobile);
				 } 
		     }); 
			getMemberLevelList("query");
			
		}else{
			
			 base.tips_error(data["message"]);
		}
	
	}
	
	base.cancelLoading();
	
}


/**
 * 重置参数
 */
function resetSearchParams(){
	
	beginDate="";
	endDate="";
	beginCredits="";
	endCredits="";
	memberType="";
	realname="";
	username="";
	mobile="";

	$("#beginDate").val("");
	
	$("#endDate").val("");
	
	$("#beginCredits").val("");
	
	$("#endCredits").val("");
	
	$("#mobile").val("");
	
	$("#realname").val("");
	
	$("#username").val("");
	
	$("#levelName").html("请选择");
	
	
}

/**
 * 搜索订单
 */
function searchMember(){
	

	
	beginDate=$("#beginDate").val();
	
	endDate=$("#endDate").val();
	
	beginCredits=$("#beginCredits").val();
	
	endCredits=$("#endCredits").val();
	
	realname=$("#realname").val();
	
	username=$("#username").val();
	
	mobile=$("#mobile").val();
	
	if(!isNull(beginCredits) && !isNumber(beginCredits)){
		
		base.tips_error("开始积分非法");
   	 
   	 	return;
		
	}
	
	if(!isNull(endCredits) && !isNumber(endCredits)){
		
		base.tips_error("结束积分非法");
   	 
   	 	return;
		
	}
    	
	
	if(!base.checkDate(beginDate,endDate))
		return;
    
    if(parseFloat(beginCredits)>parseFloat(endCredits)){
    	
    	base.tips_error("开始积分不能大于结束积分");
    	 
    	return;
    }
   
    getQueryMemberList(1,pageSize,beginDate,endDate,beginCredits,endCredits,memberType,realname,username,mobile);
	
}


/**
 * 会员等级列表
 */
var indexDiv;
function getMemberLevelList(_div){
	
	indexDiv=_div;
	
//	DDF_AsyncRequest("POST",ddf.member.getQueryMemberLevel,"",'$ddf_member.getMemberLevelListCallBack(data)');
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.member.getQueryMemberLevel,""));
		
		getMemberLevelListCallBack(data);
		
	}))().start();
}

/**
 * 会员等级列表_回调函数
 */
function getMemberLevelListCallBack(data){
	
	
	var htmlStr="";
	for(var i=0;i<data["memberLevelListData"].length;i++){
		
		htmlStr+='<li><a href=javascript:$ddf_member.setMemberType("'+data["memberLevelListData"][i]["LEVEL_ID"]+'","'+data["memberLevelListData"][i]["LEVEL_NAME"]+'")>'+data["memberLevelListData"][i]["LEVEL_NAME"]+'</a></li>';
		
	}
	
	if(indexDiv=="add"){
		$("#levelList-add").html('<li><a href=javascript:$ddf_member.setMemberType("","请选择")>请选择</a></li>'+htmlStr);
	}else if(indexDiv=="query"){
		$("#levelList").html('<li><a href=javascript:$ddf_member.setMemberType("","请选择")>请选择</a></li>'+htmlStr);
	}else if(indexDiv=="edit"){
		$("#levelList-edit").html('<li><a href=javascript:$ddf_member.setMemberType("","请选择")>请选择</a></li>'+htmlStr);
	}
	
	
	
}

/**
 * 设置会员等级
 */
function setMemberType(_LevelId,LevelName){
	
	memberType=_LevelId;
	
	if(indexDiv=="add"){
		$("#levelName-add").html(LevelName);
	}else if(indexDiv=="query"){
		$("#levelName").html(LevelName);
	}else if(indexDiv=="edit"){
		$("#levelName-edit").html(LevelName);
	}
	
	
}



/**
 * 打开添加会员
 */
function openAddMember(){
	history.addHis(this,arguments);//增加历史
	var htmlStr="";
	 
	htmlStr += '<div id="content-header">';
	htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'",1,"$ddf_index.loadIndex","") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_member.showDiv("content0")>会员管理</a><a href="javascript:void(0)" class="current">新增会员</a></div>';
	htmlStr += '</div> ';
	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips1" ></div>';
    
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>新增会员信息</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<form class="form-horizontal">	   ';
	htmlStr += '<div class="control-group" id="control-group-username">';
	htmlStr += '<label class="control-label">用户账号：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-username" value="">';
	htmlStr += '</div>              ';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-password">';
	htmlStr += '<label class="control-label">账户密码：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="password" id="input-password" value="">';
	htmlStr += '</div>              ';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group" id="control-group-memberType">';
	htmlStr += '<label class="control-label">会员等级：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<div class="btn-group"><button data-toggle="dropdown" class="btn dropdown-toggle"><span id="levelName-add">请选择</span>&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu" id="levelList-add"></ul></div>   <div class="btn-group" id="payStatusDiv" style="display:none;" ><button data-toggle="dropdown" class="btn dropdown-toggle"><span id="payStatusName">全部</span>&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu"></ul></div>';
	htmlStr += '</div>              ';
	htmlStr += '</div>';
	
	
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">证件类型：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<div class="btn-group">';
	htmlStr += '<button data-toggle="dropdown" class="btn dropdown-toggle" ><span id="card_type_name">身份证</span>&nbsp;&nbsp;<span class="caret"></span></button>';
	htmlStr += '<ul class="dropdown-menu">';
	htmlStr += '<li><a href=javascript:$ddf_member.setCardType(1,"身份证")>身份证</a></li>';
	htmlStr += '<li><a href=javascript:$ddf_member.setCardType(2,"军人证")>军人证</a></li>';
	htmlStr += '<li><a href=javascript:$ddf_member.setCardType(3,"户口本")>户口本</a></li>';
	htmlStr += '</ul>';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-identity">';
	htmlStr += '<label class="control-label">证件号码：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-identity" value="">';
	htmlStr += '</div>       ';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">用户性别：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<label><input type="radio" name="sex" value="1" checked="checked" />男</label><label><input type="radio" name="sex" value="0"/>女</label>   ';
	htmlStr += '</div>';
	htmlStr += '</div>';

/*	htmlStr += '<div class="control-group" id="control-group-card">';
	htmlStr += '<label class="control-label">卡号：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-card">       ';
	htmlStr += '</div>                    ';
	htmlStr += '</div>';*/
	htmlStr += '<div class="control-group" id="control-group-phoneNumber">';
	htmlStr += '<label class="control-label">联系电话：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-phoneNumber" value="">';
	htmlStr += '</div>                  ';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-email">';
	htmlStr += '<label class="control-label">邮箱地址：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-email" value="">';
	htmlStr += '</div>             ';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-mobile">';
	htmlStr += '<label class="control-label">手机号码：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-mobile" value="">';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-realName">';
	htmlStr += '<label class="control-label">会员姓名：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += ' <input class="span9" type="text" id="input-realName" value="">';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-memoName">';
	htmlStr += '<label class="control-label">会员备注名：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += ' <input class="span9" type="text" id="input-memoName" value="">';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-address">';
	htmlStr += '<label class="control-label">所在地址：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-address" value="">';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="form-actions">';
	htmlStr += '<button class="btn btn-primary" type="button" onclick="$ddf_member.saveMember()" >保存</button> ';
	htmlStr += '<button class="btn btn-info" type="button" onClick=$ddf_member.showDiv("content0")>返回</button>  ';
	htmlStr += '</div>  ';
	htmlStr += '</form>';
	htmlStr += '</div>';
	htmlStr += '</div>  ';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div> ';
	
//	$("#content0").css("display","none");
//	
//	$("#content1").css("display","block");
	
	showDiv("content1");
	
	$("#content1").html(htmlStr);
	
	getMemberLevelList("add");
	
	setRadioStyle();
	
	$("#input-username").change(function() {
		
		var userName=$("#input-username").val();
		
		if(isNull(userName)){
			addErrorMessage("control-group-username","input-username","用户账号不能为空");
		}else if(isLength(userName,50)){
			addErrorMessage("control-group-username","input-username","用户账号长度不能大于50字节");
		}else{
		    clearErrorMessage("control-group-username");
		}
		
	});
	
	
	
	$("#input-password").change(function() {
		
		var password=$("#input-password").val();
		
		if(isNull(password)){
			addErrorMessage("control-group-password","input-password","用户密码不能为空");
		}else if(!isLoginPassword(password)){
			addErrorMessage("control-group-password","input-password","用户密码长度为6~20位");
		}
		else{
			clearErrorMessage("control-group-password");
		}
		
	});
	
	
	$("#input-identity").change(function() {
		
		var identity=$("#input-identity").val();
		
		if(isNull(identity)){
			addErrorMessage("control-group-identity","input-identity","证件号码不能为空");
		}else if(isLength(identity,50)){
			addErrorMessage("control-group-identity","input-identity","证件号码长度不能大于50字节");
		}else{
			
			clearErrorMessage("control-group-identity");
			
		}
		
	});
	
	
/*	$("#input-card").change(function() {
		
		var card=$("#input-card").val();
		
		if(!isNull(card) && !isNumber(card)){
			addErrorMessage("control-group-card","input-card","卡号只能是数字");
		}else if(isLength(card,50)){
			addErrorMessage("control-group-card","input-card","卡号长度不能大于50字节");
		}else{
			clearErrorMessage("control-group-card");
		}
		
	});*/
	$("#input-phoneNumber").change(function() {
		
		var phoneNumber=$("#input-phoneNumber").val();
		
		if(!isPhone(phoneNumber)){
			addErrorMessage("control-group-phoneNumber","input-phoneNumber","联系电话非法");
		}else{
			clearErrorMessage("control-group-phoneNumber");
		}
		
	});
	$("#input-mobile").change(function() {
		
		var mobile=$("#input-mobile").val();
		
		if(!isMobile(mobile)){
			addErrorMessage("control-group-mobile","input-mobile","手机号码非法");
		}else{
			clearErrorMessage("control-group-mobile");
		}
		
	});
	$("#input-email").change(function() {
		
		var email=$("#input-email").val();
		
		if(!isEmail(email)){
			addErrorMessage("control-group-email","input-email","邮箱地址非法");
		}else{
			clearErrorMessage("control-group-email");
		}
		
	});
	
}


/**
 * 保存会员
 */
function saveMember(){
	
	var userName=$("#input-username").val();
	
	var password=$("#input-password").val();
	
	var identity=$("#input-identity").val();
	
	var sex=$('input[name="sex"]:checked').val();
	
	//var card=$("#input-card").val();
	
	var phoneNumber=$("#input-phoneNumber").val();
	
	var email=$("#input-email").val();
	
	var mobile=$("#input-mobile").val();
	
	var realName=$("#input-realName").val();
	
	var memoname=$("#input-memoname").val();
	
	var address=$("#input-address").val();
	
	if(isNull(userName) || isLength(userName,50)){
		addErrorMessage("control-group-username","input-username","用户账号非法");
		return;
	}
	
	if(isNull(password)){
		addErrorMessage("control-group-password","input-password","用户密码非法");
		return;
	}else if(!isLoginPassword(password)){
		addErrorMessage("control-group-password","input-password","用户密码长度为6~20位");
		return;
	}
	
	if(memberType==""){
		addErrorMessage("control-group-memberType","levelName-add","请选择会员等级");
		return;
	}
	
	if(isNull(identity) || (!isNull(identity) && !isNumber(identity))){
		addErrorMessage("control-group-identity","input-identity","证件号码非法");
		return;
	}
/*	
	if(!isNull(card) && !isNumber(card)){
		addErrorMessage("control-group-card","input-card","卡号非法");
		return;
	}*/
	
	if(!isPhone(phoneNumber)){
		addErrorMessage("control-group-phoneNumber","input-phoneNumber","联系电话非法");
		return;
	}
	
	if(!isEmail(email)){
		addErrorMessage("control-group-email","input-email","邮箱地址非法");
		return;
	}
	
	if(!isMobile(mobile)){
		addErrorMessage("control-group-mobile","input-mobile","手机号码非法");
		return;
	}
	
	var params={
			
			"userName":userName,
			"password":MD5(password),
			"identifyTypeId":identifyTypeId,
			"identity":identity,
			"sex":sex,
			//"card":card,
			"email":email,
			"phoneNumber":phoneNumber,
			"mobile":mobile,
			"realName":realName,
			"memberType":memberType,
			"memoName":memoname,
			"address":address
			
	        };

	base.showLoading();
	
	tips_index=1;
	
//	DDF_AsyncRequest("POST",ddf.member.addMcmember,params,'$ddf_member.saveMemberCallBack(data)');
    eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.member.addMcmember,params));
		
		saveMemberCallBack(data);
		
	}))().start();
	
}

/**
 * 保存会员_回调函数
 * @param data
 */
function saveMemberCallBack(data){
	
	
	if(data["code"]==1){
		
//		back("content1","content0");
		showDiv("content0");
		
		base.tips("增加会员成功");
		
		initParams();//初始化参数
		getQueryMemberList(1,pageSize,beginDate,endDate,beginCredits,endCredits,memberType,realname,username,mobile);

	}else{
		
		base.tips_error(data["message"]);
		
    }

	base.cancelLoading();
	
}



/**
 * 查询会员详情
 */
function loadMemberDetail(_userId){
	history.addHis(this,arguments);//增加历史
	selectUserId=_userId;
	
	var htmlStr="";
	
	htmlStr += '<div id="content-header">';
	htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_member.showDiv("content0")>会员管理</a><a href="javascript:void(0)" class="current">会员详情</a></div>';
	htmlStr += '</div>    ';

	htmlStr += '<div class="container-fluid">';

	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips2" ></div>';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon">';
	htmlStr += '<i class="icon-pencil"></i>';
	htmlStr += '</span>';
	htmlStr += '<h5>操作</h5>';
	htmlStr += '</div>      ';
	htmlStr += '<div class="widget-content">';
	htmlStr += '<div class="div-btn" id="top-menu-btn">';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>             ';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>会员详情</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<div class="form-horizontal">';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">会员代码：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_memberId"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">会员账号：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_userName"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">备注名：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_memoname"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">用户性别：</label>';
	htmlStr += '<div class="controls" id="show_sex">';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">邮箱地址：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_email"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">联系电话：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_phoneNumber"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">手机号码：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_mobile"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>          ';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">所在地址：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_address"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	
/*	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">卡号：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_card"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>';*/
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">生日：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_birthday"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>          ';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">会员等级：</label>';
	htmlStr += '<div class="controls" id="show_memberType">';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">消费积分：</label>';
	htmlStr += '<div class="controls" id="show_credits">';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">用户姓名：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_realName"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>          ';
	
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
//	$("#content0").css("display","none");
	
//	$("#content3").css("display","none");//防止点击快捷菜单的时候出现重叠
//	
//	$("#content4").css("display","none");//防止点击快捷菜单的时候出现重叠
//	
//	$("#content5").css("display","none");//防止点击快捷菜单的时候出现重叠
	
//	$("#content2").css("display","block");
	showDiv("content2");
	
	$("#content2").html(htmlStr);
	
	
		
	var params={
			
			"userId":selectUserId
			
	        };
	
	base.showLoading();
	
	tips_index=2;
		
//	DDF_AsyncRequest("POST",ddf.member.getQueryMemberDetail,params,'$ddf_member.loadMemberDetailCallBack(data)');
      
	  eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.member.getQueryMemberDetail,params));
			
			loadMemberDetailCallBack(data);
			
		}))().start();
	
}

/**
 * 用户详情回调函数
 */
var memberArray={};
function loadMemberDetailCallBack(data){
	
	
	var htmlStr="";
	
	if(data["code"]==1){
		$("#show_memberId").html(data["MEMBER_ID"]);
		$("#show_userName").html(data["USER_NAME"]);
		$("#show_memoname").html(data["MEMO_NAME"]);
		$("#show_email").html(data["EMAIL"]);
		if(data["SEX"]=="1"){
			$("#show_sex").html('<span class="inp_span">男</span>');
		}else if(data["SEX"]=="0"){
			$("#show_sex").html('<span class="inp_span">女</span>');
		}else{
			$("#show_sex").html('<span class="inp_span">保密</span>');
		}
		$("#show_phoneNumber").html(data["PHONE_NUMBER"]);
		$("#show_mobile").html(data["MOBILE"]);
		$("#show_realName").html(data["REAL_NAME"]);
		$("#show_credits").html(data["CREDITS"]);
		$("#show_birthday").html(data["BIRTHDAY"]);
		//$("#show_card").html(data["CARD"]);
		$("#show_address").html(data["ADDRESS"]);
		$("#show_memberType").html(data["LEVEL_NAME"]);
		
		
		memberArray["MEMBER_ID"]=data["MEMBER_ID"];
		memberArray["USER_NAME"]=data["USER_NAME"];
		memberArray["MEMO_NAME"]=data["MEMO_NAME"];
		memberArray["EMAIL"]=data["EMAIL"];
		memberArray["SEX"]=data["SEX"];
		memberArray["PHONE_NUMBER"]=data["PHONE_NUMBER"];
		memberArray["MOBILE"]=data["MOBILE"];
		memberArray["REAL_NAME"]=data["REAL_NAME"];
		memberArray["CREDITS"]=data["CREDITS"];
		memberArray["BIRTHDAY"]=data["BIRTHDAY"];
		//memberArray["CARD"]=data["CARD"];
		memberArray["ADDRESS"]=data["ADDRESS"];
		memberArray["LEVEL_NAME"]=data["LEVEL_NAME"];
		
		
		
//		htmlStr += '<button class="btn btn-success" type="button" onClick=$ddf_member.editMemberDetial("'+selectUserId+'","'+data["MEMBER_ID"]+'","'+data["USER_NAME"]+'","'+data["EMAIL"]+'","'+data["SEX"]+'","'+data["PHONE_NUMBER"]+'","'+data["MOBILE"]+'","'+data["REAL_NAME"]+'","'+data["CREDITS"]+'","'+data["BIRTHDAY"]+'","'+data["CARD"]+'","'+data["ADDRESS"]+'","'+data["LEVEL_NAME"]+'","'+data["MEMO_NAME"]+'")>修改会员信息</button> ';
//		htmlStr += '<button class="btn btn-success" type="button" onClick=$ddf_member.getMemberOrderList("'+selectUserId+'","'+data["USER_NAME"]+'","'+data["REAL_NAME"]+'")>订单明细</button> ';
		
		htmlStr += '<button class="btn btn-success" type="button" onClick=$ddf_member.editMemberDetial("'+selectUserId+'")>修改会员信息</button> ';
		htmlStr += '<button class="btn btn-success" type="button" onClick=$ddf_member.getMemberOrderList("'+selectUserId+'","'+data["USER_NAME"]+'","'+data["REAL_NAME"]+'")>订单明细</button> ';
	}else{
		
		base.tips_error(data["message"]);
		
	}
	
	htmlStr += '<button class="btn btn-info" type="button" onClick=$ddf_member.showDiv("content0")>返回</button>';

	$("#top-menu-btn").html(htmlStr);
		
	base.cancelLoading();
	
	if(updateMemberFlag){
		
		base.tips("编辑会员成功");
		
		updateMemberFlag=false;
	}
	
	
}


/**
 * 编辑资料
 */
//function editMemberDetial(selectUserId,MEMBER_ID,USER_NAME,EMAIL,SEX,PHONE_NUMBER,MOBILE,REAL_NAME,CREDITS,BIRTHDAY,CARD,ADDRESS,LEVEL_NAME,MEMO_NAME){
function editMemberDetial(_selectUserId){
	history.addHis(this,arguments);//增加历史
	var htmlStr="";
	
	

	htmlStr += '<div id="content-header">';
	htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'",1,"$ddf_index.loadIndex","") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_member.showDiv("content0")>会员管理</a><a href="javascript:void(0)" class="current">修改会员信息</a></div>';
	htmlStr += '</div>';
	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">             ';
	htmlStr += '<div id="alert-tips3" ></div>';
	
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>修改用户信息</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<form class="form-horizontal">	          	';
	htmlStr += ' <div class="control-group">';
	htmlStr += ' <label class="control-label">会员代码：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="edit_memberId">'+memberArray["MEMBER_ID"]+'</span>';
	htmlStr += '<input type="hidden" id="edit_userId" value="'+_selectUserId+'"/>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += ' <div class="control-group">';
	htmlStr += ' <label class="control-label">用户账号：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="edit_userName">'+memberArray["USER_NAME"]+'</span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group" id="control-group-memoname">';
	htmlStr += '<label class="control-label">备注名：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input type="text" id="edit_memoname" value="'+memberArray["MEMO_NAME"]+'"/>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group" id="control-group-identity">';
	htmlStr += '<label class="control-label">会员等级：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="edit_levelName">'+memberArray["LEVEL_NAME"]+'</span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group" id="control-group-identity">';
	htmlStr += '<label class="control-label">消费积分：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="edit_credits">'+memberArray["CREDITS"]+'</span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">用户性别：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<label>';
	if(memberArray["SEX"]=="1"){
		
		htmlStr += '<span class="inp_span" >男</span>';

	}else if(memberArray["SEX"]=="0"){
		
		htmlStr += '<span class="inp_span" >女</span>';

	}else{
		htmlStr += '<span class="inp_span" >保密</span>';
	}
	htmlStr += '</div>          ';
	htmlStr += '</div>';

/*	htmlStr += '<div class="control-group" id="control-group-card">';
	htmlStr += '<label class="control-label">卡号：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="edit-card">'+memberArray["CARD"]+'</span>';
	htmlStr += '</div>                      ';
	htmlStr += '</div>';*/
	
	htmlStr += '<div class="control-group" id="control-group-birthday">';
	htmlStr += '<label class="control-label">生日：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="birthday">'+memberArray["BIRTHDAY"]+'</span>';
	htmlStr += '</div>                          ';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group" id="control-group-phoneNumber">';
	htmlStr += '<label class="control-label">联系电话：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="edit-phoneNumber">'+memberArray["PHONE_NUMBER"]+'</span>';
	htmlStr += '</div>                          ';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-email">';
	htmlStr += '<label class="control-label">邮箱地址：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="edit-email">'+memberArray["EMAIL"]+'</span>';
	htmlStr += '</div>                          ';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-mobile">';
	htmlStr += '<label class="control-label">手机号码：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="edit-mobile">'+memberArray["MOBILE"]+'</span>';
	htmlStr += '</div>                          ';
	htmlStr += '</div>                ';
	htmlStr += '<div class="control-group" id="control-group-realName">';
	htmlStr += '<label class="control-label">用户姓名：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="edit-realName">'+memberArray["REAL_NAME"]+'</span>';
	htmlStr += '</div>                          ';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-address">';
	htmlStr += '<label class="control-label">所在地址：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="edit-address">'+memberArray["ADDRESS"]+'</span>    ';
	htmlStr += '</div>                          ';
	htmlStr += '</div>';
	htmlStr += '<div class="form-actions">';
	htmlStr += '<button class="btn btn-primary" type="button" onClick=$ddf_member.updateMember("'+memberArray["MEMBER_ID"]+'") >保存</button> ';
	htmlStr += '<button class="btn btn-info" type="button" onClick=$ddf_member.showDiv("content2")>返回</button>';
	htmlStr += '</div>  ';
	htmlStr += '</form>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	
	$("#content1").html("");//清楚增加用户的DIV，是为了防止input的ID重复
	showDiv("content3");
//	$("#content2").css("display","none");
	
	$("#content3").html(htmlStr);
	
//	$("#content3").css("display","block");
//	showDiv("content3");
	setRadioStyle();
	
/*	$("#edit-card").change(function() {
		
		var card=$("#edit-card").val();
		
		if(!isNull(card) && !isNumber(card)){
			addErrorMessage("control-group-card","edit-card","卡号非法");
		}else{
			clearErrorMessage("control-group-card");
		}
		
	});*/
	$("#edit-phoneNumber").change(function() {
		
		var phoneNumber=$("#edit-phoneNumber").val();
		
		if(!isPhone(phoneNumber)){
			addErrorMessage("control-group-phoneNumber","edit-phoneNumber","联系电话非法");
		}else{
			clearErrorMessage("control-group-phoneNumber");
		}
		
	});
	$("#edit-mobile").change(function() {
		
		var mobile=$("#edit-mobile").val();
		
		if(!isMobile(mobile)){
			addErrorMessage("control-group-mobile","edit-mobile","手机号码非法");
		}else{
			clearErrorMessage("control-group-mobile");
		}
		
	});
	$("#edit-email").change(function() {
		
		var email=$("#edit-email").val();
		
		if(!isEmail(email)){
			addErrorMessage("control-group-email","edit-email","邮箱地址非法");
		}else{
			clearErrorMessage("control-group-email");
		}
		
	});

	
}



/**
 * 修改会员资料
 */

var updateMemberFlag=false;

function updateMember(memberId){
		
	var memoName = $("#edit_memoname").val();
	var mobile=$("#edit-mobile").val();
	
	var realName=$("#edit-realName").val();
	/*var sex=$('input[name="sex"]:checked').val();
	
	var card=$("#edit-card").val();
	
	var phoneNumber=$("#edit-phoneNumber").val();
	
	var email=$("#edit-email").val();
	
	
	var address=$("#edit-address").val();
	
	var birthday=$("#birthday").val();
	
	
	if(!isNull(card) && !isNumber(card)){
		addErrorMessage("control-group-card","exit-card","卡号非法");
		return;
	}
	
	if(!isPhone(phoneNumber)){
		addErrorMessage("control-group-phoneNumber","exit-phoneNumber","联系电话非法");
		return;
	}
	
	if(!isEmail(email)){
		addErrorMessage("control-group-email","exit-email","邮箱地址非法");
		return;
	}
	
	if(!isMobile(mobile)){
		addErrorMessage("control-group-mobile","exit-mobile","手机号码非法");
		return;
	}*/
	
	var params={
			/*"userId":_userId,
			"rsUser.sex":sex,
			"rsUser.card":card,
			"rsUser.phoneNumber":phoneNumber,
			"rsUser.email":email,
			"rsUser.mobile":mobile,
			"rsUser.realName":realName,
			"rsUser.address":address,
			"rsUser.birthday":birthday,*/
			"memberId":memberId,
			"memoName":memoName
	        };
	
	

	tips_index=3;
	
	base.showLoading();
	
	
//	DDF_AsyncRequest("POST",ddf.member.editMemberById,params,'$ddf_member.updateMemberCallBack(data)');
	   eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.member.editMemberById,params));
			
			updateMemberCallBack(data);
			
		}))().start();
	
	
}
/**
 * 修改会员资料_回调函数
 */
function updateMemberCallBack(data){
	
	if(data["code"]==1){
		
		
		updateMemberFlag=true;
		
//		back("content3","content2");
		showDiv("content2");
	
		loadMemberDetail($("#edit_userId").val());

		
	}else{
		
		updateMemberFlag=false;
		
		 base.tips_error(data["message"]);
		 
		
	}
	base.cancelLoading();
	
}

/**
 * 会员订单明细
 */
function getMemberOrderList(_userId,_userName,_realName){	
	history.addHis(this,arguments);//增加历史
	
	var formIndex=4;
	
	var order=require("../../../shop/js/order/order");
	
	/**
	 * 第1个参数：formIndex是要在哪个DIV中显示订单列表
	 * 第2个参数：点击列表中返回按钮，显示的DIV下标
	 * 第3个参数：订单列表与订单明细是在两个DIV显示，所以当前下标与当前下标的下一个值会被占用
	 */
	order.setParams(formIndex,2,_userId,_userName,_realName);
	
	//加载页面
	order.init(order);
	
}











/**
 * 选择证件类型
 */

var identifyTypeId="1";

function setCardType(type,name){
	
	
	identifyTypeId=type;
	
	$("#card_type_name").html(name);
	
}






function showDiv(block){
	
	$("#content > div").hide();
	
	if($("#"+block).length<=0){
		
		$("#content").append('<div id="'+block+'"></div>'); 
		
	}else{
		
		$("#"+block).show();
	}
}


//暴露方法
 exports.getQueryMemberList = getQueryMemberList;
 exports.getQueryMemberListCallBack =getQueryMemberListCallBack;

 exports.resetSearchParams=resetSearchParams;
 exports.searchMember=searchMember;
exports.getMemberLevelListCallBack=getMemberLevelListCallBack;
exports.setMemberType=setMemberType;
exports.openAddMember=openAddMember;
exports.saveMember=saveMember;
exports.saveMemberCallBack=saveMemberCallBack;
exports.loadMemberDetail=loadMemberDetail;
exports.loadMemberDetailCallBack=loadMemberDetailCallBack;
exports.editMemberDetial=editMemberDetial;
exports.updateMember=updateMember;
exports.getMemberOrderList=getMemberOrderList;
exports.updateMemberCallBack=updateMemberCallBack;
exports.setCardType=setCardType;
exports.getQueryMemberListCallBack=getQueryMemberListCallBack;
exports.showDiv = showDiv;
});
